package com.stud.system.controller.workflow;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.stud.common.annotation.Log;
import com.stud.common.core.controller.BaseController;
import com.stud.common.core.domain.Result;
import com.stud.common.core.page.TableDataInfo;
import com.stud.common.enums.BusinessType;
import com.stud.common.utils.poi.ExcelUtil;
import com.stud.system.domain.WorkflowDefinitionTask;
import com.stud.system.service.WorkflowDefinitionTaskService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 流程定义任务Controller
 *
 * @author Stud
 * @date 2023-03-06
 */
@Tag(name = "流程定义任务")
@RestController
@RequestMapping("/system/workflowDefinitionTask")
@RequiredArgsConstructor
public class WorkflowDefinitionTaskController extends BaseController {

    private final WorkflowDefinitionTaskService workflowDefinitionTaskService;

    @Operation(summary = "查询流程定义任务列表")
    @PreAuthorize("@ss.hasPermi('system:workflowDefinitionTask:list')")
    @GetMapping("/list")
    public TableDataInfo<WorkflowDefinitionTask> list(WorkflowDefinitionTask workflowDefinitionTask) {
        startPage();
        Wrapper<WorkflowDefinitionTask> wrapper = new QueryWrapper(workflowDefinitionTask);
        List<WorkflowDefinitionTask> list = workflowDefinitionTaskService.list(wrapper);
        return getDataTable(list);
    }

    @Operation(summary = "导出流程定义任务列表")
    @PreAuthorize("@ss.hasPermi('system:workflowDefinitionTask:export')")
    @Log(title = "流程定义任务", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WorkflowDefinitionTask workflowDefinitionTask) {
        Wrapper<WorkflowDefinitionTask> wrapper = new QueryWrapper(workflowDefinitionTask);
        List<WorkflowDefinitionTask> list = workflowDefinitionTaskService.list(wrapper);
        ExcelUtil<WorkflowDefinitionTask> util = new ExcelUtil<WorkflowDefinitionTask>(WorkflowDefinitionTask.class);
        util.exportExcel(response, list, "流程定义任务数据");
    }

    @Operation(summary = "获取流程定义任务详细信息")
    @PreAuthorize("@ss.hasPermi('system:workflowDefinitionTask:query')")
    @GetMapping(value = "/{id}")
    public Result<WorkflowDefinitionTask> getInfo(@PathVariable("id") Long id) {
        return Result.ok(workflowDefinitionTaskService.getById(id));
    }

    @Operation(summary = "新增流程定义任务")
    @PreAuthorize("@ss.hasPermi('system:workflowDefinitionTask:add')")
    @Log(title = "流程定义任务", businessType = BusinessType.INSERT)
    @PostMapping
    public Result<Boolean> add(@Validated @RequestBody WorkflowDefinitionTask workflowDefinitionTask) {
        return Result.ok(workflowDefinitionTaskService.save(workflowDefinitionTask));
    }

    @Operation(summary = "修改流程定义任务")
    @PreAuthorize("@ss.hasPermi('system:workflowDefinitionTask:edit')")
    @Log(title = "流程定义任务", businessType = BusinessType.UPDATE)
    @PutMapping
    public Result<Boolean> edit(@Validated @RequestBody WorkflowDefinitionTask workflowDefinitionTask) {
        return Result.ok(workflowDefinitionTaskService.update(workflowDefinitionTask));
    }

    @Operation(summary = "删除流程定义任务")
    @PreAuthorize("@ss.hasPermi('system:workflowDefinitionTask:remove')")
    @Log(title = "流程定义任务", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public Result<Boolean> remove(@PathVariable Long[] ids) {
        return Result.ok(workflowDefinitionTaskService.removeByIds(ids));
    }
}
